package com.oneday.nuo.base.controller;

import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.oneday.nuo.base.dto.NuoAuthDTO;
import com.oneday.nuo.base.dto.NuoMenuDTO;
import com.oneday.nuo.base.entity.NuoAuthEntity;
import com.oneday.nuo.base.response.NuoResult;
import com.oneday.nuo.base.service.NuoAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 权限表(NuoAuth)表控制层
 *
 * @author liushuai
 * @since 2021-03-13 23:36:49
 */
@RestController
@RequestMapping("api/auth")
@Api(tags="NuoAuthController")
@ApiModel(value = "",description = "权限接口")
public class NuoAuthController {
    @Autowired
    private NuoAuthService nuoAuthService;

    @ApiOperation(value = "新增权限" ,  notes="新增权限")
    @PostMapping("saveAuth")
    public NuoResult saveAuth(@RequestBody NuoAuthDTO nuoAuthDTO){
        nuoAuthService.saveAuth(nuoAuthDTO);
        return NuoResult.buildResponseSave();
    }
    @ApiOperation(value = "根据权限Id查询权限" ,  notes="根据权限Id查询权限")
    @GetMapping("queryByAuthId")
    public NuoResult queryByAuthId(@RequestParam String authId){
        NuoAuthEntity entity = nuoAuthService.queryByAuthId(authId);
        return NuoResult.buildResponseQuery(entity);
    }

    @ApiOperation(value = "根据权限Id删除权限" ,  notes="根据权限Id删除权限")
    @GetMapping("deleteByAuthId")
    public NuoResult deleteByAuthId(@RequestParam String authId){
        nuoAuthService.deleteByAuthId(authId);
        return NuoResult.buildResponseDelete();
    }
    @ApiOperation(value = "根据参数分页查询" ,  notes="根据参数分页查询")
    @GetMapping("queryAuthPageByParam")
    public NuoResult queryAuthPageByParam(Page page, NuoAuthDTO nuoAuthDTO){
        IPage<NuoAuthEntity> pageList = nuoAuthService.queryAuthPageByParam(page,nuoAuthDTO);
        return NuoResult.buildResponseQuery(pageList);
    }
    @ApiOperation(value = "查询所有权限",notes = "查询所有权限")
    @GetMapping("queryAuthAll")
    public NuoResult queryAuthAll(){
        List<Tree<String>> auths = nuoAuthService.queryAuthAll();
        return NuoResult.buildResponseQuery(auths);
    }



}